package sd.czw.com.mmgapp.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import sd.czw.com.mmgapp.R;
import sd.czw.com.mmgapp.model.shouyebean.HomeInfo;

/**
 * Created by czw
 * desc 描述：
 * on 2017/7/6.
 */
public class PinpaiRvAdapter extends RecyclerView.Adapter<PinpaiRvAdapter.MyViewHolder> {

    private Context context;
    private List<HomeInfo.ErrmsgBean.ImgBean.PinpaiImgBean>  datas;

    public PinpaiRvAdapter(Context context, List<HomeInfo.ErrmsgBean.ImgBean.PinpaiImgBean>  datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.hsv_image, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (datas != null){
            Glide.with(context).load(datas.get(position).getUrl()).placeholder(new ColorDrawable(Color.parseColor("#f5f5f5"))).into(holder.hsvImg);
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.hsv_img)
        ImageView hsvImg;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
